<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="con">123456</div>
    <button id="btn">发送验证码</button>
  </body>
  <script>
    var timeObj
    document.getElementById('btn').onclick = function () {
      document.getElementById('con').innerHTML = randNum(100000, 999999)
      this.disabled = true
      var n = 60,
        timeObj = setInterval(function () {
          document.getElementById('btn').innerHTML = n-- + 's后重新发送'
          if (n == 0) {
            document.getElementById('btn').disabled = false
            document.getElementById('btn').innerHTML = '发送验证码'
            clearInterval(timeObj)
          }
        }, 1000)
    }
    //指定范围随机数
    function randNum(min, max) {
      return Math.floor(Math.random() * (max - min) + 1) + min
    }
  </script>
</html>
